import 'package:coinbaby/common/const/cosnt.dart';
import 'package:coinbaby/login&regist/login.dart';
import 'package:coinbaby/root/root.dart';
import 'package:coinbaby/router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: const Color(0xff5C96EA),
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
        primaryTextTheme: TextTheme(headline6: TextStyle(color: AppColor.font333,fontSize: 17,fontWeight: FontWeight.normal)),
      ),
      debugShowCheckedModeBanner: false,
      onGenerateRoute: onGenerateRoute,
      initialRoute: "/",
    );
  }
}


class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {



  Future<Widget> _init() async {
    final share = await SharedPreferences.getInstance();
    if(share.getBool(AppConst.APP_IS_LOGIN) == true) {
      return RootPage();
    } else {
      return LoginPage();
    }
  }

  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.transparent, animate: true);
    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return FutureBuilder(
      future: _init(),
      initialData: Container(color: Colors.red,),
      builder: (context, snapshot){
        return snapshot.data;
      },
    );
  }
}